<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<title>Using The Library</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="generator" content="Doc-O-Matic" />
    <meta http-equiv="Content-Style-Type" content="text/css" />
    <link rel="STYLESHEET" href="default.css" type="text/css" />

<script type="text/javascript" src="scripts.js"></script>
</head>
<body class="Element700" onload="onBodyLoadEx('frames.html', 'topic', '00596.html');" onmousedown="onBodyMouseDown();">

<!-- Begin Popups -->

<!-- End Popups -->

<!-- Begin Page Header -->
<div class="Element710" id="areafixed">
<div class="Element94">
<a href="00675.html" target="topic">Software Libraries Help</a> &gt; <a href="00591.html" target="topic">I2C Bit Bang Library Help</a> &gt; <a href="00596.html" target="topic">Using The Library</a></div>
<div class="Element92">
<table width="100%" cellspacing="0" cellpadding="0">
<tr><td width="25%">
<div class="Element1">
MPLAB Harmony Core Help</div>
</td><td width="25%">
<div class="Element2">
<a href="contents.html" target="tocidx">Contents</a> | <a href="00007.html" target="topic">Home</a></div>
</td><td width="25%">
<div class="Element90">
<a href="00587.html" target="topic">Previous</a> | <a href="00591.html" target="topic">Up</a> | <a href="00592.html" target="topic">Next</a></div>
</td><td width="25%">
<div class="Element96">
<a href="mailto:docerrors@microchip.com&subject=MPLAB Harmony Documentation Feedback (Topic ID: I2C Bit Bang Using the Library Topic Title: Using The Library)&body=Thank you for your feedback! Please include a description of your feedback, and indicate whether you are reporting an an error in the documentation or an enhancement.">Documentation Feedback</a><br> <a href="http://support.microchip.com" target="_blank">Microchip Support</a></div>
</td></tr></table><div class="Element5">
Using The Library</div>
</div>
</div>

<!-- End Page Header -->

<!-- Begin Client Area -->
<div class="Element720" id="areascroll">
<div class="Element721">

<!-- Begin Page Content -->
<a name="PageContent"></a><div class="Element58">
<a name="4465736372697074696F6E"></a><div class="Element11">
<div class="Element10">
<p class="Element10">
The I2C bit bang library supports the following I2C transfers:&nbsp;</p>
<p class="Element10">
&nbsp;</p>
<ul class="Element630">
<li class="Element600">Master Write: The master writes a block of data to the slave</li>
<li class="Element600">Master Read: The master reads a block of data from the slave</li>
<li class="Element600">Master Write/Read: The master writes and then reads back a block of data from slave.</li>
</ul><p class="Element10">
&nbsp;</p>
<p class="Element10">
The block of data is transferred in a non-blocking manner using the timer peripheral interrupt. Application can register a callback to get notified when the I2C transfer is complete.&nbsp;</p>
<p class="Element10">
&nbsp;</p>
<p class="Element10">
The example code demonstrates write operation using callback method.&nbsp;</p>
<p class="Element10">
&nbsp;</p><div class="Element13"><div class="Element12"><pre class="Element12"><strong><span style="color: #000080">#define</span></strong> APP_SLAVE_ADDR 0x0057
<strong><span style="color: #000080">#define</span></strong> NUM_BYTES      10

uint8_t myWriteData [NUM_BYTES] = {'1', '0', ' ', 'B', 'Y', 'T', 'E', 'S', '!', '!',};

<strong><span style="color: #000080">void</span></strong> I2C_BB_Callback(uintptr_t context)
{
    <strong><span style="color: #000080">if</span></strong>(I2C_BB_ErrorGet() == I2CBB_ERROR_NONE)
    {
        <i><span style="color: #008000">//Transfer is completed successfully</span></i>
    }
    <strong><span style="color: #000080">else</span></strong>
    {
        <i><span style="color: #008000">//Error occurred during transfer.</span></i>
    }
}

<strong><span style="color: #000080">int</span></strong> main(<strong><span style="color: #000080">void</span></strong>)
{
    <i><span style="color: #008000">/* Register Callback function */</span></i>
    I2C_BB_CallbackRegister(I2C_BB_Callback, (uintptr_t)NULL);

    <i><span style="color: #008000">/* Submit Write Request */</span></i>
    I2C_BB_Write(APP_SLAVE_ADDR, &amp;myWriteData[0], NUM_BYTES);

    <i><span style="color: #008000">/* Perform other tasks. The I2C_BB_Callback will be called when the write transfer is complete */</span></i>
}</pre></div></div>
</div>
</div>
</div>
<!-- End Page Content -->

<!-- Begin Page Footer -->
<div class="Element95">
<a href="00675.html" target="topic">Software Libraries Help</a> &gt; <a href="00591.html" target="topic">I2C Bit Bang Library Help</a> &gt; <a href="00596.html" target="topic">Using The Library</a></div>
<div class="Element93">
<table width="100%" cellspacing="0" cellpadding="0">
<tr><td width="25%">
<div class="Element3">
MPLAB Harmony Core Help</div>
</td><td width="25%">
<div class="Element4">
<a href="contents.html" target="tocidx">Contents</a> | <a href="00007.html" target="topic">Home</a></div>
</td><td width="25%">
<div class="Element91">
<a href="00587.html" target="topic">Previous</a> | <a href="00591.html" target="topic">Up</a> | <a href="00592.html" target="topic">Next</a></div>
</td><td width="25%">
<div class="Element97">
<a href="mailto:docerrors@microchip.com&subject=MPLAB Harmony Documentation Feedback (Topic ID: I2C Bit Bang Using the Library Topic Title: Using The Library)&body=Thank you for your feedback! Please include a description of your feedback, and indicate whether you are reporting an an error in the documentation or an enhancement.">Documentation Feedback</a><br> <a href="http://support.microchip.com" target="_blank">Microchip Support</a></div>
</td></tr></table></div>

<!-- End Page Footer -->
</div>
</div>

<!-- End Client Area -->
</body></html>